#include "stdafx.h"
#include "ServiceObject.h"

CServiceObject::CServiceObject(void)
{

}

CServiceObject::~CServiceObject(void)
{

}

bool	CServiceObject::Push(DWORD msg, BYTE* wParam,size_t wParamSize, BYTE* lParam,size_t lParamSize)
{
	return m_msgQueue.Push(msg,wParam,wParamSize,lParam,lParamSize);
}
bool	CServiceObject::PushFront(DWORD msg, BYTE* wParam,size_t wParamSize, BYTE* lParam,size_t lParamSize)
{
	return m_msgQueue.PushFront(msg,wParam,wParamSize,lParam,lParamSize);
}

void	CActiveService::SetPerformance(float f)
{

}
void	CActiveService::OnInstall()
{
	m_msgQueue.Init(10000,new fge::SystemMemAllotor());
	StartThread();
}
void	CActiveService::OnUninstall()
{
	m_msgQueue.PushFront(0,0,0,0,0);
	CThread::Close();
	WaitForCompletion();
}

void	CActiveService::ThreadProc()
{
	fge::SMSG* pMsg=0;
	unsigned n(0);
	while(true)
	{		
		pMsg = m_msgQueue.Pop();
		if(pMsg){
			if(0 == pMsg->msg) break;
			MsgProc(pMsg->msg,(WPARAM)pMsg->wParam,(LPARAM)pMsg->lParam);
		} 	
		m_plugMag.Update();

		n = (n+1)&255;
		if( !n ) ::Sleep(10);
	}
	m_plugMag.UninstallPlugin();
}
void	CActiveService::ClearThreadRes( )
{	
}
bool	CActiveService::Start()
{
	OnInstall( );
	return true;
}
void	CActiveService::Close()
{
	OnUninstall( );
}